package com.atguigu.srb.base.algorithm;


import org.springframework.util.StopWatch;
import org.web3j.abi.datatypes.Int;

import java.math.BigDecimal;

class Solution {

    public static Long count(Long n){
        if(n == 1 || n == 2){
            return n;
        }
        return count(Long.valueOf(n-1)) + count(Long.valueOf(n-2));
    }

    public static Long sum(Long n){
        if(n ==1 || n == 2){
            return n;
        }
        Long a = 1l;
        Long b = 2l;
        Long c = 0l;
        for (int i = 0; i < n-2; i++) {
            c = a + b;
            a = b;
            b = c;
        }
        return c;
    }
    public  static void main(String[] args) {
        //Integer 结果是：-1109825406  int 能表示的范围是0～655350～-2^16-1)
        //时间少了差不多一半
        StopWatch sw = new StopWatch("时长");
        sw.start();
        Long count = count(50l);
        sw.stop();
        System.out.println("时长" + sw.prettyPrint());
        System.out.println("方式：" + count);

        StopWatch sw2 = new StopWatch("时长2");
        sw2.start();
        Long count2 = sum(50l);
        sw2.stop();
        System.out.println("时长" + sw2.prettyPrint());
        System.out.println("方式2："  + count2);


    }
}

